﻿using System;
using System.Collections.Generic;
using Castle.ActiveRecord;
using Atendex.Dominio.Interfaces;

namespace Atendex.Dominio.ActiveRecord
{
    [ActiveRecord("atendimento")]
    [Serializable]
    public class AtendimentoAR : ActiveRecordBase<AtendimentoAR>, IAtendimento
    {
        private AtendimentoAR()
        {
            
        }
        internal AtendimentoAR(IAtendente atendente)
        {
            Atendente = atendente;
            Status = StatusAtendimento.Pendente;
            OrdensServico = new List<IOrdemServico>();
            Ativo = true;
        }

        [PrimaryKey]
        public int Id { get; private set; }

        [Property]
        public DateTime? DataFim { get; set; }

        [Property]
        public DateTime? DataInicio { get; set; }

        [Property]
        public StatusAtendimento Status { get; set; }

        [BelongsTo(Type = typeof (AtendenteAR), Cascade = CascadeEnum.All)]
        public IAtendente Atendente { get; set; }

        [BelongsTo(Type = typeof (SolicitanteAR), Cascade = CascadeEnum.All)]
        public ISolicitante Solicitante { get; set; }

        [HasMany(typeof (OrdemServicoAR), Cascade = ManyRelationCascadeEnum.AllDeleteOrphan, Inverse = false)]
        public IList<IOrdemServico> OrdensServico { get; set; }

        [Property]
        public bool Visivel { get; set; }

        [Property]
        public bool Ativo { get; set; }

        public bool Valido
        {
            get { return Solicitante != null && Atendente != null && OrdensServico != null && OrdensServico.Count > 0; }
        }




    }
}